import router from './index'
import store from '../store/index'
const Home = () => import("../views/Home");
function getAsyncRoutes(routes) { 
  // console.log(routes,'4')
  const res = []
  routes.forEach(route => { // 所有菜单都是二级结构，一级没有页面功能，所以只要添加二级菜单的路由
    if (route.children.length !== 0) {
      const children = []
      route.children.forEach(menu => { // 二级菜单需匹配页面
        children.push({
          path: menu.menuItemUrl,
          name: menu.menuItemNm,
          key: menu.key,
          // 此处也可使用require
          component: () => import(`@/views${menu.menuItemUrl}`),
          meta: { processForm: menu.processForm,validInd:menu.validInd }
        })
      })
      res.push({
        path: '/Home',
        name: route.menuItemNm,
        component: Home,
        children: children
      })
    }
  })
  
  // 将菜单提取出来的路由加到路由表
  router.addRoutes(res);

  router.options.routes = res; 
  // console.log(router.options.routes)

  store.commit("SET_MENUS", res);
  // 暂存菜单到本地
  localStorage.setItem("MenuArr",JSON.stringify(res)) 
return res
}
export default getAsyncRoutes


